<template>
  <div class="user-management-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="12">
        <el-select
          v-model="queryForm.roleId"
          clearable
          placeholder="请选择所属角色"
        >
          <el-option
            v-for="item in options2"
            :key="item.id"
            :label="item.classifyName"
            :value="item.id"
            @click.native="chooseone(item)"
          />
        </el-select>

        <!-- <el-button
          icon="el-icon-plus"
          type="primary"
          @click="handleEdit($event)"
        >
          添加
        </el-button> -->
        <!-- <el-button
          icon="el-icon-delete"
          type="danger"
          @click="handleDelete($event)"
        >
          批量删除
        </el-button> -->
      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="12">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model="queryForm.keyWoard"
              clearable
              placeholder="请输入用户名"
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      border
      :data="list"
      @selection-change="setSelectRows"
    >
      <el-table-column align="center" show-overflow-tooltip type="selection" />
      <!-- <el-table-column align="center" label="序号" width="55">
        <template #default="{ $index }">
          {{ $index + 1 }}
        </template>
      </el-table-column> -->
      <el-table-column
        align="center"
        label="id"
        prop="id"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="职位标题"
        prop="jobHead"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="联系人"
        prop="linkmans"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="职位内容"
        prop="jobInfo"
        show-overflow-tooltip
        width="250"
      />
      <el-table-column
        align="center"
        label="联系人手机号"
        prop="linkphone"
        show-overflow-tooltip
      />
      <el-table-column align="center" label="事项上架" show-overflow-tooltip>
        <template slot-scope="scope">
          <template v-if="scope.row.isactivity == 0">
            <span style="color: red">未上架</span>
          </template>

          <template v-else-if="scope.row.isactivity == 1">
            <span style="color: green">已上架</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="所属城市id"
        prop="jobCityId"
        show-overflow-tooltip
      />

      <!-- <el-table-column
        align="center"
        label="导演"
        prop="director"
        show-overflow-tooltip
      /> -->
      <el-table-column
        align="center"
        label="集合时间"
        prop="shootTime"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        label="用户管理"
        show-overflow-tooltip
        width="180"
      >
        <template #default="{ row }">
          <el-button size="small" type="text" @click="baoming(row)">
            报名管理
          </el-button>
          <el-button size="small" type="text" @click="lingdui(row)">
            领队管理
          </el-button>
        </template>
      </el-table-column>
      <el-table-column align="center" label="事项审核" show-overflow-tooltip>
        <template slot-scope="scope">
          <template v-if="scope.row.jobCheck == 0">
            <span style="color: red">事项未审核</span>
          </template>

          <template v-else-if="scope.row.jobCheck == 1">
            <span style="color: green">事项审核成功</span>
          </template>
          <template v-else-if="scope.row.jobCheck == 2">
            <span style="color: red">事项审核未通过</span>
          </template>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        label="操作"
        show-overflow-tooltip
        width="130"
      >
        <template #default="{ row }">
          <el-button type="text" @click="handleEditfour(row)">停用</el-button>
          <el-button type="text" @click="handleEdittwo(row)">处理</el-button>
        </template>
      </el-table-column>
      <template #empty>
        <el-image
          class="vab-data-empty"
          :src="require('@/assets/empty_images/data_empty.png')"
        />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <edit ref="edit" @fetch-data="fetchData" />
    <bmgl ref="bmgl" @fetch-data="fetchData" />
    <ldgl ref="ldgl" @fetch-data="fetchData" />
    <chuli ref="chuli" @fetch-data="fetchData" />
    <Editxiugai ref="Editxiugai" @fetch-data="fetchData" />
  </div>
</template>

<script>
  import { roleId } from '@/api/yanyuan'
  import { getList } from '@/api/userManagement' //doDelete,
  import edit from '../model/Editing.vue'
  import bmgl from '../model/baomingguanli.vue'
  import ldgl from '../model/lingduiguanli.vue'
  import chuli from '../model/chuli.vue'
  import Editxiugai from '../model/xiugai.vue'
  export default {
    name: 'UserManagement',
    components: { bmgl, ldgl, edit, chuli, Editxiugai },
    data() {
      return {
        list: [],
        options2: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          roleId: '', //所属角色id
          keyWoard: '', //关键字
          cityId: '', //城市id不能为空
          areaId: '', //区域id不能为空
          ageId: '', //年龄条件 id
          sex: '', //性别
        },
      }
    },
    created() {
      this.fetchDatatwo()
      this.fetchData()
    },
    methods: {
      async chooseone() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      setSelectRows(val) {
        this.selectRows = val
      },
      handleEdit(row) {
        //编辑
        if (row.id) {
          this.$refs['edit'].showEdit(row)
        } else {
          this.$refs['edit'].showEdit()
        }
      },
      handleEdittwo(row) {
        //处理
        if (row.id) {
          this.$refs['chuli'].showEdit(row)
        } else {
          this.$refs['chuli'].showEdit()
        }
      },
      baoming(row) {
        //报名管理
        if (row.id) {
          this.$refs['bmgl'].showEdit(row)
        } else {
          this.$refs['bmgl'].showEdit()
        }
      },
      lingdui(row) {
        console.log(row.jobId)
        //领队管理
        if (row.id) {
          this.$refs['ldgl'].showEdit(row)
        } else {
          this.$refs['ldgl'].showEdit()
        }
      },
      handleEditfour(row) {
        //停用
        if (row.id) {
          this.$refs['Editxiugai'].showEdit(row)
        } else {
          this.$refs['Editxiugai'].showEdit()
        }
      },
      // handleDelete(row) {
      //   if (row.id) {
      //     this.$baseConfirm('你确定要删除当前项吗', null, async () => {
      //       const { msg } = await doDelete({ id: row.id })
      //       this.$baseMessage(msg, 'success', 'vab-hey-message-success')
      //       await this.fetchData()
      //     })
      //   } else {
      //     if (this.selectRows.length > 0) {
      //       const id = this.selectRows.map((item) => item.id).join()
      //       this.$baseConfirm('你确定要删除选中项吗', null, async () => {
      //         const { msg } = await doDelete({ id })
      //         this.$baseMessage(msg, 'success', 'vab-hey-message-success')
      //         await this.fetchData()
      //       })
      //     } else {
      //       this.$baseMessage('未选中任何行', 'error', 'vab-hey-message-error')
      //     }
      //   }
      // },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      async fetchDatatwo() {
        let queryForm = {}
        const res = await roleId(queryForm)
        this.options2 = res.data
        console.log(res)
      },
      async fetchData() {
        this.listLoading = true
        const res = await getList(this.queryForm)
        console.log(res.code)
        if (res.code == 0) {
          this.$baseMessage(
            '访问错误请联系管理员',
            'error',
            'vab-hey-message-error'
          )
        }
        this.list = res.data.dataList
        this.total = res.data.total
        this.listLoading = false
      },
    },
  }
</script>
